/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package test.controller;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;
import test.hibernate.dao.CustomerDao;
import test.hibernate.pojo.Customer;

/**
 *
 * @author mamat
 */
public class DeleteCustomerController extends MultiActionController {
    public ModelAndView delete(HttpServletRequest arg0, HttpServletResponse arg1) throws Exception {
        CustomerDao customerDao = (CustomerDao) getApplicationContext().getBean("CustomerDao");
        String id = arg0.getParameter("id");
        List<Customer> list = customerDao.getCustomerId(Integer.parseInt(id));
        Customer c = (Customer)list.get(0);
        customerDao.deleteCustomer(c);
        return new ModelAndView("redirect:list.htm");
    }
}
